import { DevTest } from '../services/api';

function method(str, a, b) {
  let type = 'string';
  if (str === 'updateTime') {
    type = 'date';
  } else if (str === 'progId') {
    type = 'num';
  }
  switch (type) {
    case 'num': // 数字排序
      return a - b;
    case 'date': // 日期排序，IE8下'2012-12-12'这种格式无法设置时间，替换成'/'
      return moment(a).unix() - moment(b).unix();
    default:
      // 字符串排序
      return a.localeCompare(b);
  }
}
export default {
  namespace: 'devtest',

  state: {
    list: [],
    pagination: {},
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      const response = yield call(DevTest, payload);

      const dataSource = response.devTestReps;
      //console.log('devtest', dataSource);
      const result = {
        list: Array.isArray(response.devTestReps) ? dataSource : [],
        pagination: {
          total: response.pageInfo.pageTotal,
        },
      };

      //console.log('log', result);
      yield put({
        type: 'save',
        payload: result,
      });
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        list: action.payload.list,
        pagination: action.payload.pagination,
      };
    },
  },
};
